greatcfandomcom-20200214-history
Introduction to Programming
Introduction to Programming for Software Development Many introductions to programming concentrate on a language rather than the process of developing applications that are reliable. This has the unfortunate side effect that many bad practices can be picked up through poor code examples. Added to this many software developers tend to believe that being skilled in one language is all that is needed for software development, yet there are many calls in the literature (Ford, 2008; Loui, 2008) for polyglot language developers. This introduction will take an extreme approach to teaching using Best Practice Education in a style similar to Test Driven Development (TDD). The idea is that this Introduction to Programming will form the outline for the introduction and various specific introductions will be based on this. At the moment the following specific instances are under development: * Introduction to CSharp * Introduction to Python * Introduction to Bash * Introduction to DOS * Introduction to PowerShell Specification, Refinement Using Proofs, Implementation and Testing What we are aiming at is to start with a formal specification, for example in Z (this is only a first attempt at the Sort example JasonCozens 20:32, November 24, 2009 (UTC)): We then refine this specification proving each step, hopefully using automated tools. Create an implementation, and test the implementation with tests generated from the specification. Programming by Proof and Test The ultimate aim of this course will be to teach you to create correct software using proof and tests as quickly as the more traditional less rigorous methods. This is a big ask but the pay offs will be enormous. If we can write correct programs quickly then we can spend more time in development and less in maintenance. Ideally maintenance should be solely concerned with feature changes and not bugs. Characteristics of a Good Test We've now written our first simple program and a test. So what makes a good test? * Repeatable * Automated * Failure is Specific * Executes Quickly * Has few dependencies In this list we are really defining the characteristics of "unit" tests. Repeatable One of the most important characteristics of a test is that it should be repeatable. It is no use if a test gives different results each time it is run with the same inputs. The results of a test are often not repeatable if we have missed dependencies in a test. The data can be valid only at certain times. An example of a test that passed most of the time was a test that relied upon a date. In the test a new date was created that added a month to an existing date. Unfortunately the person that had written this piece of code hadn't taken into account the year. So that the test would fail in December as the new date was earlier in the year and not in the next year. This error was similar in nature to the Y2K problem. It was however the test that was wrong and not the code being tested. Automated Failure is Specific Example 1 - Hello world "Hello, world" is the starting point in many introductory texts. It is good in that ideally a working program is created quickly that illustrates all the important points in constructing an executable. Example 1 - Hello World Components We want to start by specifying this program. * Write Hello World. * Write a test script. * Write a build system to: ** Build the application ** Run the tests ** Record the results of the test * Link the application back to its source and the build. * Look at a specification for the application * Prove the implementation meets the specification Example 2 - Hello World with Python and the Bash Shell Throughout this course we will use a variety of software tools. It is important to be conversant with different tools (). print "Hello, world." Run this in a bash shell: $python hello.py hello, world. $ Create a file of the expected output. Hello, world. Write first test as a bash script. python hello.py > actual.py diff expected.py actual.py Example 2 - Hello World with Python Testing Example N - Stream Editors In this example we will start with something very specific. We want to create the wiki text for a four week interval of daily hits. Period Header Week 1 Section Week 2 Section Week 3 Secion Week 4 Section We will create this structure using a chain of processing blocks. The first block will produce a stream of commands. The next block will process the header. The next block will process the sections. StartData ---> Create Commands ---> Process Header ---> Process Section ---> Wiki-Output ---> Process Section Header ---> Process Table ---> The language: ::= "CMD" ::= "MkHeader" | "MkSection" Category:Education Category:Introduction